#include "ReadFile.h"

#include <QFile>
#include <QDebug>
#include <QSettings>

QString ReadFile::readQssFile(QString filePath)
{
    QFile file(filePath);
    if(!file.open(QIODevice::ReadOnly))
    {
        qWarning() << filePath << "文件打开失败";
        return "";
    }

    QString str;
    str = QString(file.readAll());
    file.close();
    return str;
}

Tcp_Config ReadFile::readTcpConfigFile(QString filePath)
{
    QSettings settings(filePath, QSettings::IniFormat);
    Tcp_Config config;
    config.serverIP = settings.value("Tcp_IP/ServerIP").toString();
    config.serverPort = settings.value("Tcp_IP/ServerPort").toInt();
    return config;
}

QByteArray ReadFile::readFile(QString filePath)
{
    QFile file(filePath);
    if(!file.open(QIODevice::ReadOnly))
    {
        qWarning() << filePath << "文件打开失败";
        return "";
    }
    QByteArray array;
    array = file.readAll();
    file.close();
    return array;
}

ReadFile::ReadFile(QObject *parent)
    : QObject{parent}
{}
